package com.hzdl.car.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.car.bean.Check;
import com.hzdl.car.bean.Customer;
import com.hzdl.car.bean.Rent;
import com.hzdl.car.mapper.CarMapper;
import com.hzdl.car.mapper.CheckMapper;
import com.hzdl.car.mapper.RentMapper;
import com.hzdl.car.service.CheckService;

import com.hzdl.car.vo.CarVo;
import com.hzdl.car.vo.CheckVo;
import com.hzdl.car.vo.RentVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class CheckServiceImpl implements CheckService {
    @Resource
    private CheckMapper checkMapper;
    @Resource
    private CarMapper carMapper;
    @Resource
    private RentMapper rentMapper;
    @Override
    public int addCheck(CheckVo checkVo) {
        int row=0;
        RentVo rentVo=new RentVo();
        rentVo.setRentId(checkVo.getRentId());
        rentVo.setRentFlag(1);
        //修改出租单状态
        row+=rentMapper.RentIsFlag(rentVo);
        Rent rent=rentMapper.findCarNById(rentVo);
        CarVo carVo=new CarVo();
        carVo.setIsrenting(0);
        carVo.setCarNumber(rent.getCarNumber());
        //修改汽车状态
        row+=carMapper.carIsRent(carVo);
        row+=checkMapper.addCheck(checkVo);
        return row;
    }

    @Override
    public int delCheck(CheckVo checkVo) {
        return checkMapper.delCheck(checkVo);
    }

    @Override
    public int updateCheck(CheckVo checkVo) {
        return checkMapper.updateCheck(checkVo);
    }

    @Override
    public PageInfo<Check> findCheck(CheckVo checkVo) {
        PageHelper.startPage(checkVo.getPage(),checkVo.getLimit());
        List<Check> list=checkMapper.findCheck(checkVo);
        PageInfo<Check> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }
}
